package com.example.maple.ccsclient.presenter;

import android.content.Context;

import com.example.maple.ccsclient.interfaces.ILackView;
import com.example.maple.ccsclient.model.AllDataInfoUtils;
import com.example.maple.ccsclient.model.DataModel;
import com.example.maple.ccsclient.model.ISendData;
import com.example.maple.ccsclient.model.LackModel;
import com.example.maple.ccsclient.model.PicModel;

import java.util.List;

/**
 * Created by maple on 2016/7/6.
 */
public class LackPresenter {

	//页码
	int page = 1;
	AllDataInfoUtils mAllDataInfoUtils = null;
	Context mContext;
	ILackView mILackView;

	public LackPresenter(ILackView iLackView, Context context) {
		mILackView = iLackView;
		mContext = context;
		mAllDataInfoUtils= new AllDataInfoUtils(mContext);
	}

	//如果不刷新，则再次页码上+1并且进行请求
	public void getLack(final boolean isRefresh) {

		if (isRefresh) {
			page = 1;
			mILackView.startAnimation();
		} else {
			page += 1;
		}

		mAllDataInfoUtils.getLackInfo(page, new ISendData() {
			@Override
			public void sendData(Object o) {
				DataModel<Object> info = (DataModel<Object>) o;

				//当获取完网络数据时候，停止动画
				mILackView.stopAnimation();

				if (info.getStatus() == 1) {
					mILackView.showLack((List<LackModel>) info.getData(), isRefresh);

				} else {
					//显示错误信息
					mILackView.showDialog(info.getInfo());
				}
			}
		});


	}
}
